package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.FamilyMemberData;
import com.zzyl.nursing.dto.FamilyOrElderDto;
import com.zzyl.nursing.dto.PageDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/member/user")
@Api(tags =  "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto){
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody FamilyOrElderDto elderFamilyAddDto){
        familyMemberService.addFamily(elderFamilyAddDto);
        return success();
    }

    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult my(){
        List<FamilyMemberElder> family = familyMemberService.getFamily();
        return success(family);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("分页查询")
    public AjaxResult listByPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        List<FamilyMemberData> listPage =familyMemberService.listByPage(pageNum,pageSize);
        return success(listPage);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation("解绑")
    public AjaxResult deleteById(@RequestParam Long id){
        familyMemberService.deleteById(id);
        return success();
    }





}